/**
 *  by fdj
 */
 
 window.CardLove = window.CardLove || {};
 
 /**
 * canvas对象
 */
 
CardLove.Canvas = function(){
	var canvas = $("#js_canvas");
	return canvas;
}

/**
 * context对象
 */
CardLove.Context = function(){
	var canvas = CardLove.Canvas();
	var c = canvas.get(0).getContext("2d");
	return c;
}

/**
 * 文字格式
 */
 CardLove.DrawText = function(color, t, x, y){
	var c = CardLove.Context();
	c.font = "15px Tahoma";
	c.textAlign= "center";
	c.fillStyle= color;
	c.textBaseline = "top";
	c.fillText(t,x,y);
}

/**
 * 载入图片
 */
 CardLove.DrawImages = function(url, x, y, t){
	var c = CardLove.Context();
	
	var img = new Image();
	img.src = url;
	
	//t为true，正放图片，否则横放图片
	if(t){
		c.drawImage(img, x, y, img.width, img.height);
	}else{
		
		c.drawImage(img, x, y, 150, 80);
	}
}

/**
 * 清除canvas
 */
 CardLove.clearCanvas = function(){
	var canvas = CardLove.Canvas();
	var cwidth = canvas.width();
	var cheight = canvas.height();
	var c = CardLove.Context();

	c.clearRect(0, 0, cwidth, cheight);
}
